package com.ruoyi.epidemic.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.epidemic.domain.EpidemicUserDept;
import com.ruoyi.epidemic.mapper.EpidemicUserDeptMapper;
import com.ruoyi.epidemic.service.IEpidemicUserDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert;

import static com.ruoyi.common.utils.ShiroUtils.getLoginName;

/**
 * 疫情防控用户-部门信息Service业务层处理
 *
 * @author ruoyi
 * @date 2022-04-05
 */
@Service
public class EpidemicUserDeptServiceImpl implements IEpidemicUserDeptService
{
    @Autowired
    private EpidemicUserDeptMapper epidemicUserDeptMapper;

    /**
     * 查询疫情防控用户-部门信息
     *
     * @param id 疫情防控用户-部门信息主键
     * @return 疫情防控用户-部门信息
     */
    @Override
    public EpidemicUserDept selectEpidemicUserDeptById(Long id)
    {
        return epidemicUserDeptMapper.selectEpidemicUserDeptById(id);
    }

    /**
     * 查询疫情防控用户-部门信息列表
     *
     * @param epidemicUserDept 疫情防控用户-部门信息
     * @return 疫情防控用户-部门信息
     */
    @Override
    public List<EpidemicUserDept> selectEpidemicUserDeptList(EpidemicUserDept epidemicUserDept)
    {
        return epidemicUserDeptMapper.selectEpidemicUserDeptList(epidemicUserDept);
    }

    /**
     * 新增疫情防控用户-部门信息
     *
     * @param epidemicUserDept 疫情防控用户-部门信息
     * @return 结果
     */
    @Override
    public int insertEpidemicUserDept(EpidemicUserDept epidemicUserDept)
    {
        epidemicUserDept.setCreateTime(DateUtils.getNowDate());
        epidemicUserDept.setCreateBy(getLoginName());
        return epidemicUserDeptMapper.insertEpidemicUserDept(epidemicUserDept);
    }

    /**
     * 修改疫情防控用户-部门信息
     *
     * @param epidemicUserDept 疫情防控用户-部门信息
     * @return 结果
     */
    @Override
    public int updateEpidemicUserDept(EpidemicUserDept epidemicUserDept)
    {
        epidemicUserDept.setUpdateTime(DateUtils.getNowDate());
        epidemicUserDept.setUpdateBy(getLoginName());
        return epidemicUserDeptMapper.updateEpidemicUserDept(epidemicUserDept);
    }

    /**
     * 批量删除疫情防控用户-部门信息
     *
     * @param ids 需要删除的疫情防控用户-部门信息主键
     * @return 结果
     */
    @Override
    public int deleteEpidemicUserDeptByIds(String ids)
    {
        return epidemicUserDeptMapper.deleteEpidemicUserDeptByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除疫情防控用户-部门信息信息
     *
     * @param id 疫情防控用户-部门信息主键
     * @return 结果
     */
    @Override
    public int deleteEpidemicUserDeptById(Long id)
    {
        return epidemicUserDeptMapper.deleteEpidemicUserDeptById(id);
    }

    @Override
    public int selectCountByUserIdAndDeptId(Long userId, Long deptId) {
        return epidemicUserDeptMapper.selectCountByUserIdAndDeptId(userId,deptId);
    }

    @Override
    public int bindUserDeptBash(String userId, String deptId) {

        int i = epidemicUserDeptMapper.selectCountBashByUserId(userId);
        if(i > 0){
            i = epidemicUserDeptMapper.updateUserDeptBash(userId, deptId);
        } else {
            i = epidemicUserDeptMapper.bindUserDeptBash(userId, deptId);
        }

        return i;
    }
}
